package com.flow.odr.control.login;

import com.flow.odr.control.base.BaseController;
import com.flow.odr.utils.ResultModel;
import com.flow.odr.utils.ResultTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  @Author: Yan
 *  @Date: 2020/3/11
 *  @Description: 登录接口
 */
@Slf4j
@Controller
@RequestMapping(value = "/login")
public class LoginController extends BaseController {

    /**
     *  @Author: Yan
     *  @Date: 2020/3/11
     *  @Description: 跳转登录html页面
     */
    @GetMapping(value = "")
    public String login() {
        return BASEWEBMOBILE + "login/login";
    }

    /**
     *  @Author: Yan
     *  @Date: 2020/3/11
     *  @Description: 登录验证 用户名、密码和验证码
     */
    @ResponseBody
    @PostMapping(value = "/into")
    public ResultModel login(String loginName,String passWord,String validateCode){
        /** 验证验证码是否正确 */
        String validate = (String) getSession("validate");  // 后台存储验证码
        if (StringUtils.isEmpty(validateCode) || !validateCode.equals(validate)) {
            return ResultTools.fail("验证码错误!");
        }
        return ResultTools.success();
    }

    /**
     *  @Author: Yan
     *  @Date: 2020/3/11
     *  @Description: 跳转首页页面地址
     */
    @GetMapping(value = "/index")
    public String index(){
        return BASEWEBMOBILE + "index/index";
    }
}
